#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int main() {
    int N, i;
    int arr[10];
    int minIndex = 0, maxIndex = 0;

    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
        if (arr[i] < arr[minIndex]) {
            minIndex = i;
        }
        if (arr[i] > arr[maxIndex]) {
            maxIndex = i;
        }
    }

    int temp = arr[0];
    arr[0] = arr[minIndex];
    arr[minIndex] = temp;

    if (maxIndex == 0) {
        maxIndex = minIndex;
    }

    temp = arr[N - 1];
    arr[N - 1] = arr[maxIndex];
    arr[maxIndex] = temp;

    for (i = 0; i < N; i++) {
        printf("%d ", arr[i]);
    }

    return 0;
}
